﻿using System;
using System.Collections;
using System.Collections.Generic;
using Game;
using Game.UI;
using UnityEngine;
using ZYLFramework.Manage;

namespace DesignerScripts
{
    public class Timeline{
        public static Dictionary<string, TimelineEvent> functions = new Dictionary<string, TimelineEvent>(){
            {"OpenUI", OpenUI},
            {"CloseUI", CloseUI},
            {"UINotifyMessageEvent", UINotifyMessageEvent},
            {"SetRoundState", SetRoundState},
        };
        
        /// <summary>
        /// 开启一个UI面板
        /// </summary>
        /// <param name="tlo"></param>
        /// <param name="args"></param>
        private static void OpenUI(TimelineObj tlo, params object[] args){
            if (args.Length <= 0) return;
            
            if (tlo.caster)
            {
                var uiEnum = (UIEnum)args[0];
                UIManage.Instance.Open(uiEnum);
            }
        }
        
        /// <summary>
        /// 关闭一个UI面板
        /// </summary>
        /// <param name="tlo"></param>
        /// <param name="args"></param>
        private static void CloseUI(TimelineObj tlo, params object[] args){
            if (tlo.caster)
            {
                UIManage.Instance.Close();
            }
        }
        
        /// <summary>
        /// 触发某个事件
        /// </summary>
        /// <param name="tlo"></param>
        /// <param name="args"></param>
        private static void UINotifyMessageEvent(TimelineObj tlo, params object[] args){
            if (args.Length <= 0) return;
            if (tlo.caster)
            {
                var eventEnum = (EventEnum)args[0];
                object[] newArgs = new object[args.Length - 1];
                Array.Copy(args, 1, newArgs, 0, args.Length - 1);
                SceneVariants.NotifyMessageEvent(eventEnum,newArgs);
            }
        }
        
        /// <summary>
        /// 设置回合的状态
        /// </summary>
        /// <param name="tlo"></param>
        /// <param name="args"></param>
        private static void SetRoundState(TimelineObj tlo, params object[] args){
            if (args.Length <= 0) return;
            if (tlo.caster)
            {
                SceneVariants.GetLevelManager().SetRoundState((RoundState)args[0]);
            }
        }
    }
}